package com.diaohw.platform.utility.uml.core;

import com.diaohw.platform.common.constant.ServiceConstant;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Getter
@Setter
public class UMLOptions {
    /**
     * 基础包
     */
    private String basePackage = ServiceConstant.basePackage;
    /**
     * 忽略方法
     */
    private Set<String> ignoredM = Set.of("canEqual", "finalize ", "wait0", "clone", "equals", "toString", "hashCode", "getClass", "notify", "notifyAll", "wait", "builder", "createWrapper");

    /**
     * 忽略字段
     */
    private Set<String> ignoredF = Set.of("serialVersionUID");
    /**
     * 忽略getter和setter
     */
    private boolean ignoredGetterAndSetter = true;
    /**
     * 递归拼接Feign接口
     */
    private boolean recursionFeign = false;

    /**
     * 生成的图片大小
     */
    private int limitSize = 8192000;

    private Map<String, String> parentRelationship = new HashMap<>();

    /**
     * 是否忽略方法
     */
    public boolean isIgnoredM(String name) {
        boolean b = ignoredM.contains(name) || name.contains("$");
        if (b) {
            return true;
        }

        if (ignoredGetterAndSetter) {
            return name.startsWith("get") ||
                    name.startsWith("is") ||
                    name.startsWith("set");
        }
        return false;
    }

    /**
     * 是否忽略字段
     */
    public boolean isIgnoredF(String name) {
        return ignoredF.contains(name) || name.contains("$");
    }


    public void setParentRelationship(String parent, String child) {
        parentRelationship.put(parent, child);
    }

    public String getParentRelationship(String child) {
        return parentRelationship.getOrDefault(child, "");
    }

}
